/////////////////////////////////////////////////////////////////////////////
//
//  PIGL 
//  WYSE (c) 2012
//  All rights received
//
/////////////////////////////////////////////////////////////////////////////

package org.kolonitsky.alexey.utils
{

    import mx.utils.ObjectUtil;

    public class ObjectUtil
    {
        /**
         *
         * @param source
         * @param distance
         */
        public static function copyProperties(source:Object, distance:Object):void
        {
            var classInfo:Object = mx.utils.ObjectUtil.getClassInfo(source);
            var isDistanceDynamic:Boolean = mx.utils.ObjectUtil.isDynamicObject(distance);
            for each (var name:QName in classInfo.properties)
                if (name in distance || isDistanceDynamic)
                    distance[name] = source[name];
        }

        /**
         *
         * @param source
         * @param distance
         * @return
         */
        public static function mergeObject(source:Object, distance:Object):int
        {
            var result:int = 0;
            var classInfo:Object = mx.utils.ObjectUtil.getClassInfo(source);
            var isDistanceDynamic:Boolean = mx.utils.ObjectUtil.isDynamicObject(distance);
            for each (var name:QName in classInfo.properties)
            {
                if (name in distance || isDistanceDynamic)
                {
                    distance[name] = source[name];
                    result++;
                }
            }
            return result;
        }
    }
}
